<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .square{
            width: 200px;
            height: 200px;
            display: inline-block;
            background-color: #e5e5e5;
            box-shadow: 1px 1px 4px #000;
        }
        .red{
            background-color: red;
            border-radius: 20px;
        }
    </style>
</head>
<body>
    <div id="demo">

    </div>
    <div>
        <button id="btn1">正方形</button>
        <button id="btn2">红色</button>
        <button id="btn3">切换</button>
        <button id="btn4">清空所有类</button>
    </div>
</body>
<script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.6.3.js"></script>
<script>
     $("#btn1").click(function(){
        //给demo元素加一个square的类
        $("#demo").addClass("square")
    })
    $("#btn2").click(function(){
        //给demo元素加一个red的类
        $("#demo").addClass("red square")
    })
    $("#btn3").click(function(){
        $("#demo").toggleClass("square")
        $("#btn4").click(function(){
        //没有参数清空所有类
        //有参数清空填写类（可以是多个）
        $("#demo").removeClass("red")
    })
    })
</script>
</html>